﻿using AutoMapper;
using DFGK.IRepository;
using DFGK.IService;
using DFGK_WMS.Model.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;

namespace DFGK.Service
{
    public class CachePortService : BaseService, ICachePortService
    {
        private readonly ICachePortRepository _cachePortRepository;
        private readonly IUnitOfWork _unitOfWork;
        public CachePortService(IMapper mapper, ICachePortRepository cachePortRepository, IUnitOfWork unitOfWork) : base(mapper)
        {
            _cachePortRepository = cachePortRepository;
            _unitOfWork = unitOfWork;
        }

        public bool AddCachePort(CachePort m, out string message)
        {
            message = string.Empty;
            var cobj = _cachePortRepository.QueryIsEntityWhere(x => x.Code == m.Code);
            if (cobj != null)
            {
                message = "编码已存在！";
                return false;
            }
            _cachePortRepository.AddEntity(m);
            return _unitOfWork.SaveChangesEntity();
        }

        public List<CachePort> GetCachePortList(int pageIndex, int pageSize, out int totalCount)
        {
            var clist = _cachePortRepository.GetEntityAlls();
  
            var list = _cachePortRepository.GetEntityAlls(clist, pageIndex, pageSize, out totalCount, x => x.CreateDate, false);
            return list.ToList();
        }
    }
}
